<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';

import { useFs } from '@fast-crud/fast-crud';

import { DefTenantApi, listByBizId } from '#/api';
import { FileBizTypeEnum } from '#/enums/commonEnum';

import { createCrudOptions } from '../data/view-crud';

const formRef = ref();
const { crudBinding } = useFs({ createCrudOptions });

const { currentRoute } = useRouter();

onMounted(async () => {
  const { params } = currentRoute.value;
  const id = params.id as string;
  const row = await DefTenantApi.get(id);

  const logos = await listByBizId({
    bizId: id,
    bizType: FileBizTypeEnum.DEF_TENANT_LOGO,
  });
  row.logo = logos[0]?.id;

  formRef.value.setFormData(row, { mergeForm: false });
});
</script>

<template>
  <div class="p-8">
    <FsForm ref="formRef" v-bind="crudBinding.viewForm" />
  </div>
</template>
